package com.lanou.myapplication.database;


import android.app.Application;
import android.content.Context;

import com.lanou.myapplication.database.greendao.DaoMaster;
import com.lanou.myapplication.database.greendao.DaoSession;


/**
 * Created by dllo on 15/11/5.
 */
public class GrenDaoApplication extends Application {
    private static DaoMaster daoMaster;//daomaster是为了获得daoSession对象
    private static DaoSession daoSession;//会话
    private static Context context;

    //使用静态方法
    public static DaoMaster getDaoMaster() {
        if (daoMaster == null) {

            //创建一个新的OpenHelper
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, "lanou3g", null);//1.静态方法里面使用静态变量
            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return daoMaster;
    }

    //单例
    public static DaoSession getDaoSession() {
        if (daoSession == null) {
            if (daoMaster == null) {
                getDaoMaster();
                daoSession = daoMaster.newSession();
            }

        }
        return daoSession;

    }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();

        context = this;//context获得值
    }

}